package preparedStatement;

import util.jdbc_utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


// 利用preparedStatement 更新语句
public class preparedStatement_TestSelect {
    public static void main(String[] args) throws SQLException {

        Connection connection = jdbc_utils.get_connection();

        //区别:
        //使用 ？ 占位符代替参数，插入语句
        String sql ="select * from `users` where id =?";


        PreparedStatement Statement = connection.prepareStatement(sql);//需要一个预编译SQL，先写SQL，不执行

        //手动给参数赋值
        Statement.setInt(1,1);

        ResultSet resultSet = Statement.executeQuery();

        while (resultSet.next()){
            System.out.println(resultSet.getObject(1));
            System.out.println(resultSet.getObject(2));
            System.out.println(resultSet.getObject(3));
            System.out.println(resultSet.getObject(4));
            System.out.println(resultSet.getObject(5));

            System.out.println("----------------------------------------------------------");
        }



        jdbc_utils.release(connection,Statement,resultSet);

    }
}
